package com.atguigu.daijia.payment.config;

import com.atguigu.daijia.common.constant.MqConst;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author XiangLiang
 * @Since 2025/1/2 11:12
 * @Description: ProfitSharingMqConfig类 - 分账MQ配置类，商户系统至少要2分钟之后才可以申请分账，使用MQ延迟消息执行分账
 */
@Configuration
public class ProfitSharingMqConfig {
    @Bean
    public Queue profitSharingQueue() {
        // 第一个参数是创建的queue的名字，第二个参数是是否支持持久化
        return new Queue(MqConst.QUEUE_PROFIT_SHARING, true);
    }

    @Bean
    public CustomExchange profitSharingExchange() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");
        return new CustomExchange(MqConst.EXCHANGE_PROFIT_SHARING, "x-delayed-message", true, false, args);
    }

    @Bean
    public Binding bindingCancel() {
        return BindingBuilder.bind(profitSharingQueue()).to(profitSharingExchange()).with(MqConst.ROUTING_PROFIT_SHARING).noargs();
    }
}
